<!DOCTYPE html><html lang="en"><head><title>GetAuthorization.aspx</title></head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"><meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0"><meta name="groc-relative-root" content=""><meta name="groc-document-path" content="GetAuthorization.aspx"><meta name="groc-project-path" content="GetAuthorization.aspx.cs"><link rel="stylesheet" type="text/css" media="all" href="assets/style.css"><script type="text/javascript" src="assets/behavior.js"></script><body><div id="meta"><div class="file-path">GetAuthorization.aspx.cs</div></div><div id="document"><div class="segment"><div class="comments "><div class="wrapper"><h1 id="getauthorization-sample">GetAuthorization Sample</h1>
<p>This sample code demonstrates how to 
retrieve an Authorization resource
API used: GET /v1/payments/authorization/{id}</p></div></div><div class="code"><div class="wrapper"><span class="hljs-keyword">using</span> System;
<span class="hljs-keyword">using</span> System.Web;
<span class="hljs-keyword">using</span> PayPal.Api;
<span class="hljs-keyword">using</span> PayPal;
<span class="hljs-keyword">using</span> System.Collections.Generic;
<span class="hljs-keyword">using</span> Newtonsoft.Json;
<span class="hljs-keyword">using</span> Newtonsoft.Json.Linq;

namespace PayPal.Sample
{
    <span class="hljs-keyword">public</span> <span class="hljs-keyword">partial</span> <span class="hljs-keyword">class</span> GetAuthorization : BaseSamplePage
    {
        <span class="hljs-keyword">protected</span> <span class="hljs-keyword">override</span> <span class="hljs-keyword">void</span> <span class="hljs-title">RunSample</span>()
        {</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h3 id="api-context">Api Context</h3>
<p>Pass in a <code>APIContext</code> object to authenticate 
the call and to send a unique request id 
(that ensures idempotency). The SDK generates
a request id if you do not pass one explicitly. 
See <a href="/Source/Configuration.html">Configuration.cs</a> to know more about APIContext.</p></div></div><div class="code"><div class="wrapper">            <span class="hljs-keyword">var</span> apiContext = Configuration.GetAPIContext();</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h3 id="payment">Payment</h3>
<p>A Payment Resource; create one with its intent set to <code>sale</code>, <code>authorize</code>, or <code>order</code></p></div></div><div class="code"><div class="wrapper">            <span class="hljs-keyword">var</span> payment = <span class="hljs-keyword">new</span> Payment()
            {
                intent = <span class="hljs-string">"authorize"</span>,</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><p>A resource representing a Payer that funds a payment. Use the List of <code>FundingInstrument</code> and the Payment Method as &#39;credit_card&#39;</p></div></div><div class="code"><div class="wrapper">                payer = <span class="hljs-keyword">new</span> Payer()
                {</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><p>The Payment creation API requires a list of
FundingInstrument; add the created <code>FundingInstrument</code>
to a List</p></div></div><div class="code"><div class="wrapper">                    funding_instruments = <span class="hljs-keyword">new</span> List&lt;FundingInstrument&gt;() 
                    {</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><p>A resource representing a Payeer&#39;s funding instrument.
Use a Payer ID (A unique identifier of the payer generated
and provided by the facilitator. This is required when
creating or using a tokenized funding instrument)
and the <code>CreditCardDetails</code></p></div></div><div class="code"><div class="wrapper">                        <span class="hljs-keyword">new</span> FundingInstrument()
                        {</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><p>A resource representing a credit card that can be used to fund a payment.</p></div></div><div class="code"><div class="wrapper">                            credit_card = <span class="hljs-keyword">new</span> CreditCard()
                            {
                                billing_address = <span class="hljs-keyword">new</span> Address()
                                {
                                    city = <span class="hljs-string">"Johnstown"</span>,
                                    country_code = <span class="hljs-string">"US"</span>,
                                    line1 = <span class="hljs-string">"52 N Main ST"</span>,
                                    postal_code = <span class="hljs-string">"43210"</span>,
                                    state = <span class="hljs-string">"OH"</span>
                                },
                                cvv2 = <span class="hljs-string">"874"</span>,
                                expire_month = <span class="hljs-number">11</span>,
                                expire_year = <span class="hljs-number">2018</span>,
                                first_name = <span class="hljs-string">"Joe"</span>,
                                last_name = <span class="hljs-string">"Shopper"</span>,
                                number = <span class="hljs-string">"4877274905927862"</span>,
                                type = <span class="hljs-string">"visa"</span>
                            }
                        }
                    },
                    payment_method = <span class="hljs-string">"credit_card"</span>
                },</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><p>The Payment creation API requires a list of transactions; add the created <code>Transaction</code> to a List</p></div></div><div class="code"><div class="wrapper">                transactions = <span class="hljs-keyword">new</span> List&lt;Transaction&gt;()
                {</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><p>A transaction defines the contract of a payment - what is the payment for and who is fulfilling it. Transaction is created with a <code>Payee</code> and <code>Amount</code> types</p></div></div><div class="code"><div class="wrapper">                    <span class="hljs-keyword">new</span> Transaction()
                    {</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><p>Let&#39;s you specify a payment amount.</p></div></div><div class="code"><div class="wrapper">                        amount = <span class="hljs-keyword">new</span> Amount()
                        {
                            currency = <span class="hljs-string">"USD"</span>,</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><p>Total must be equal to sum of shipping, tax and subtotal.</p></div></div><div class="code"><div class="wrapper">                            total = <span class="hljs-string">"107.47"</span>,
                            details = <span class="hljs-keyword">new</span> Details()
                            {
                                shipping = <span class="hljs-string">"0.03"</span>,
                                subtotal = <span class="hljs-string">"107.41"</span>,
                                tax = <span class="hljs-string">"0.03"</span>
                            }
                        },
                        description = <span class="hljs-string">"This is the payment transaction description."</span>
                    }
                }
            };</div></div></div><div class="segment"><div class="code folded"><div class="wrapper marker"><span class="c1">            // Ignore workflow code segment</span></div><div class="wrapper">            <span class="hljs-comment">// Ignore workflow code segment</span>
            <span class="hljs-preprocessor">#<span class="hljs-keyword">region</span> Track Workflow</span>
            <span class="hljs-keyword">this</span>.flow.AddNewRequest(title: <span class="hljs-string">"Create authorization for credit card payment"</span>, requestObject: payment);
            <span class="hljs-preprocessor">#<span class="hljs-keyword">endregion</span></span></div></div></div><div class="segment"><div class="comments "><div class="wrapper"><p>Create a payment by posting to the APIService
using a valid APIContext</p></div></div><div class="code"><div class="wrapper">            <span class="hljs-keyword">var</span> createdPayment = payment.Create(apiContext);</div></div></div><div class="segment"><div class="code folded"><div class="wrapper marker"><span class="c1">            // Ignore workflow code segment</span></div><div class="wrapper">            <span class="hljs-comment">// Ignore workflow code segment</span>
            <span class="hljs-preprocessor">#<span class="hljs-keyword">region</span> Track Workflow</span>
            <span class="hljs-keyword">this</span>.flow.RecordResponse(createdPayment);
            <span class="hljs-preprocessor">#<span class="hljs-keyword">endregion</span></span></div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h3 id="authorization">Authorization</h3>
<p>Retrieve an Authorization Id
by making a Payment with intent
as &#39;authorize&#39; and parsing through
the Payment object</p></div></div><div class="code"><div class="wrapper">            <span class="hljs-keyword">var</span> authorizationId = createdPayment.transactions[<span class="hljs-number">0</span>].related_resources[<span class="hljs-number">0</span>].authorization.id;

            <span class="hljs-preprocessor">#<span class="hljs-keyword">region</span> Track Workflow</span>
            <span class="hljs-comment">//--------------------</span>
            <span class="hljs-keyword">this</span>.flow.AddNewRequest(<span class="hljs-string">"Get authorization details"</span>, description: <span class="hljs-string">"ID: "</span> + authorizationId);
            <span class="hljs-comment">//--------------------</span>
            <span class="hljs-preprocessor">#<span class="hljs-keyword">endregion</span></span></div></div></div><div class="segment"><div class="comments "><div class="wrapper"><p>Get Authorization by sending
a GET request with authorization Id
to the
URI v1/payments/authorization/{id}</p></div></div><div class="code"><div class="wrapper">            <span class="hljs-keyword">var</span> authorization = Authorization.Get(apiContext, authorizationId);

            <span class="hljs-preprocessor">#<span class="hljs-keyword">region</span> Track Workflow</span>
            <span class="hljs-comment">//--------------------</span>
            <span class="hljs-keyword">this</span>.flow.RecordResponse(authorization);
            <span class="hljs-comment">//--------------------</span>
            <span class="hljs-preprocessor">#<span class="hljs-keyword">endregion</span></span></div></div></div><div class="segment"><div class="comments "><div class="wrapper"><p>For more information, please visit <a href="https://developer.paypal.com/docs/api/">PayPal Developer REST API Reference</a>.</p></div></div><div class="code"><div class="wrapper">        }

    }
}</div></div></div></div></body></html>